﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DoAnOOP.DataAccessLayer
{
    class clsLyLichGV
    {
        public DataRow LayThongTinGV()
        {
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM GIAOVIEN, KHOA WHERE GIAOVIEN.MAKHOA = KHOA.MAKHOA AND MAGIAOVIEN = \'" + frmMain.mssv+"'", clsConnect.ConnectionString);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count != 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                return dr;
            }
            else
            {
                return null;
            }
        }
        public List<DataRow> LayDanhSachKhoa()
        {
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM KHOA", clsConnect.ConnectionString);
            DataSet ds = new DataSet();
            da.Fill(ds);
            List<DataRow> listDr = new List<DataRow>();
            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    listDr.Add(ds.Tables[0].Rows[i]);
            }
            return listDr;
        }
        public bool UpdateHo(string _Ho)
        {
            string sql = "UPDATE GIAOVIEN SET HO = '" + _Ho + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateTen(string _Ten)
        {
            string sql = "UPDATE GIAOVIEN SET TEN = '" + _Ten + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateNoiSinh(string _NoiSinh)
        {
            string sql = "UPDATE GIAOVIEN SET NOISINH = '" + _NoiSinh + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateHocVi(string _HocVi)
        {
            string sql = "UPDATE GIAOVIEN SET HOCVI = '" + _HocVi + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateHocHam(string _HocHam)
        {
            string sql = "UPDATE GIAOVIEN SET HOCHAM = '" + _HocHam + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateKhoa(string _Khoa)
        {
            SqlDataAdapter da = new SqlDataAdapter("SELECT MAKHOA FROM KHOA WHERE TENKHOA = '" + _Khoa + "'", clsConnect.ConnectionString);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataRow dr = ds.Tables[0].Rows[0];
            string sql = "UPDATE GIAOVIEN SET MAKHOA = '" + dr["MAKHOA"].ToString() + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateGioi(string _Gioi)
        {
            string sql = "UPDATE GIAOVIEN SET GIOITINH = '" + _Gioi + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateNgaySinh(string _NgaySinh)
        {
            string sql = "UPDATE GIAOVIEN SET NGAYSINH = '" + _NgaySinh + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool UpdateNgayVaoLam(string _NgayVaoLam)
        {
            string sql = "UPDATE GIAOVIEN SET NGAYVAOLAM = '" + _NgayVaoLam + "' WHERE MAGIAOVIEN = '" + frmMain.mssv + "'";
            SqlCommand command = new SqlCommand(sql, clsConnect.GetSqlConnect());
            try
            {
                command.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
